﻿using Projet_IMA.Base;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Projet_IMA.Unsafe
{
    public unsafe class CachePoint
    {
        public UnsafePoint3D* p_p;
        public UnsafeColor* p_c;

        public int Lenght
        {
            get;
            private set;
        }

        public void load(List<V3> points, List<Color> colors)
        {
            UnsafePoint3D* point;
            UnsafeColor* color;

            Lenght = points.Count;
            p_p = (UnsafePoint3D*)Unsafe.UnmanagedMemory.New<UnsafePoint3D>(Lenght);
            p_c = (UnsafeColor*)Unsafe.UnmanagedMemory.New<UnsafeColor>(Lenght);

            for (int i = 0; i < Lenght; i++)
            {
                point = &p_p[i];
                color = &p_c[i];

                point->x = points[i].x;
                point->y = points[i].y;
                point->z = points[i].z;
                
                color->B = colors[i].B;
                color->G = colors[i].G;
                color->R = colors[i].R;
            }
        }

        public void Reset()
        {
            Unsafe.UnmanagedMemory.Free(p_p);
            Unsafe.UnmanagedMemory.Free(p_c);
        }
    }
}
